//
//  ViewController.m
//  chouti
//
//  Created by mini4s216 on 14/12/18.
//  Copyright (c) 2014年 mini4s216. All rights reserved.
//

#import "ViewController.h"
#import "SliderView.h"

@interface ViewController ()

@end

@implementation ViewController
{
    BOOL isHidden;
    
    UIView * shadowView;
    
    UIView * backView;
    
    SliderView * _slideView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self createUI];
    
    isHidden = YES;

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    
}

- (void)createUI
{

    backView = [[UIView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    backView.backgroundColor = [UIColor darkGrayColor];
    backView.alpha = 1.0;
    
    
    [self.view addSubview:backView];
    
    
    _slideView = [[SliderView alloc]initWithFrame:CGRectMake(backView.bounds.size.width - 200, 49, 200, backView.bounds.size.height-49)];
    _slideView.backgroundColor = [UIColor redColor];
    _slideView.tag = 10;
    
    [backView addSubview:_slideView];
    
    shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, backView.bounds.size.width- _slideView.bounds.size.width, backView.bounds.size.height)];
    shadowView.backgroundColor = [UIColor clearColor];
    
    
    UITapGestureRecognizer * tgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [shadowView addGestureRecognizer:tgr];
    [backView addSubview:shadowView];
    
    UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(backView.bounds.size.width - 200, 0, 200, 49)];
    titleLabel.text = @"哈哈哈哈";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor whiteColor];
    
    
    [backView addSubview:titleLabel];
}
- (void)tap:(UITapGestureRecognizer *)tgr
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    CGRect frame = backView.frame;
    
    frame.origin.x += self.view.bounds.size.width;
    
    backView.frame = frame;
    
    [UIView commitAnimations];
    isHidden = YES;

}

- (IBAction)OnClick:(id)sender
{
    //SliderView * sv = (SliderView *)[self.view viewWithTag:10];
    
    if (isHidden) {
        [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    CGRect frame = backView.frame;
    
    frame.origin.x -= self.view.bounds.size.width;
    
    backView.frame = frame;
    
    [UIView commitAnimations];
        isHidden = NO;
    }else{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1];
        CGRect frame = backView.frame;
        
        frame.origin.x += 200;
        
        backView.frame = frame;
        
        [UIView commitAnimations];
        isHidden = YES;

    }
    
        
}
@end
